/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.network.groupping;

import aiaudio.processing.base.mapreduce.CoordinateDoubleValueKey;
import aiaudio.lastfm.hbase.CannotCreateTableException;
import aiaudio.Application;
import aiaudio.processing.MainTableGroup;
import java.io.IOException;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;

/**
 *
 * @author nastya
 */
public class GroupTransponationAlgorithm{
    private final MainTableGroup mainTableGroup;

    public GroupTransponationAlgorithm(MainTableGroup mainTableGroup) {
        this.mainTableGroup = mainTableGroup;
    }
    
    
    
    
    public void start() throws IOException, CannotCreateTableException, InterruptedException, ClassNotFoundException {
        Job job = collectDictionariesJob();
        job.waitForCompletion(true);
    }

   private Job collectDictionariesJob() throws IOException {
        Job job = new Job();

        
        Scan scan = new Scan();
        
        String userToGroupTable = Application.database().getByName(mainTableGroup.getNetworkAlgTableGroup().getUserToGroupTable()).getDatabaseName();
        TableMapReduceUtil.initTableMapperJob(userToGroupTable, scan, GrouppingMatrixTransponationMapping.class, 
                ImmutableBytesWritable.class, CoordinateDoubleValueKey.class, job);
        
        String groupToUserTable = Application.database().getByName(mainTableGroup.getNetworkAlgTableGroup().getGroupToUserTable()).getDatabaseName();
        TableMapReduceUtil.initTableReducerJob(groupToUserTable, GrouppingMatrixTransponationReducer.class, job);
        
        return job;
    }    
    
}
